﻿/**
 * @file queue_pushpop.c
 * Copyright (c) 2021 Gaaagaa. All rights reserved.
 * 
 * @author  : Gaaagaa
 * @date    : 2021-06-02
 * @version : 1.0.0.0
 * @brief   : 对 双端队列 容器的数据进行 压入/弹出 操作。
 */

/**
 * The MIT License (MIT)
 * Copyright (c) Gaaagaa. All rights reserved.
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is furnished to do
 * so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#include "std_queue.h"
#include "std_mdebug.h"
#include <stdio.h>

////////////////////////////////////////////////////////////////////////////////

int main(int argc, char * argv[])
{
    xmdb_this_t xmdb_comm = XSTD_NULL;

    xstd_int32_t  xit_value = 0;
    xque_this_t xque_this = XSTD_NULL;

    //======================================

    xmdb_comm = (xmdb_this_t)std_mdbcomm_start();

    printf("%d. mem count : %d\n", __LINE__, (xstd_int32_t)std_mdbcomm_count());

    xque_this = std_queue_create_int32();

    printf("%d. mem count : %d, sizeof(xstd_queue_t) = %d\n",
           __LINE__,
           (xstd_int32_t)std_mdbcomm_count(),
           (xstd_int32_t)std_queue_sizeof());

    //======================================
    // push

    for (xit_value = 1; xit_value <= 100; ++xit_value)
    {
        std_queue_push_int32(xque_this, xit_value);
    }

    printf("%d. mem count : %d\n", __LINE__, (xstd_int32_t)std_mdbcomm_count());

    //======================================
    // pop

    for (xit_value = 1; std_queue_size(xque_this) > 0; ++xit_value)
    {
        printf("%3d  ", std_queue_front_int32(xque_this));
        std_queue_pop(xque_this);

        if ((0 == (xit_value & 15)) || std_queue_empty(xque_this))
            printf("\n");
    }

    printf("%d. mem count : %d\n", __LINE__, (xstd_int32_t)std_mdbcomm_count());

    //======================================

    std_queue_destroy(xque_this);

    printf("%d. mem count : %d\n", __LINE__, (xstd_int32_t)std_mdbcomm_count());

    std_mdbcomm_stop();

    //======================================

    return 0;
}

////////////////////////////////////////////////////////////////////////////////

